package com.webchat.admin.service.sys;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.exception.BusinessException;
import com.webchat.domain.vo.request.sys.SysDataDictionaryCategoryRequestVO;
import com.webchat.domain.vo.response.sys.SysDataDictionaryCategoryBaseVO;
import com.webchat.rmi.pgc.sys.SysDataDictionaryCategoryClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 数据字典分类服务
 *
 * @author SongRenShuo
 * @date 2025/06/28
 */
@Service
public class SysDataDictionaryCategoryService {

    @Autowired
    private SysDataDictionaryCategoryClient sysDataDictionaryCategoryClient;


    /**
     * 创建或者更新数据字典分类
     *
     * @param requestVO 请求 VO
     * @return {@link Long } 主键
     */
    public Long save(SysDataDictionaryCategoryRequestVO requestVO) {

        APIResponseBean<Long> apiResponseBean = sysDataDictionaryCategoryClient.save(requestVO);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return apiResponseBean.getData();
        }
        throw new BusinessException(apiResponseBean.getMsg());
    }

    /**
     * 删除数据字典分类
     *
     * @param categoryId 分类 ID
     * @param userId     用户ID
     * @return boolean
     */
    public boolean delete(Long categoryId, String userId) {

        APIResponseBean<Boolean> apiResponseBean = sysDataDictionaryCategoryClient.delete(categoryId, userId);
        if (APIResponseBeanUtil.isOk(apiResponseBean)) {
            return apiResponseBean.getData();
        }
        throw new BusinessException(apiResponseBean.getMsg());
    }

    /**
     * 分页查询
     *
     * @param code     编号
     * @param name     名称
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @return {@link APIPageResponseBean }<{@link SysDataDictionaryCategoryBaseVO }>
     */
    public APIPageResponseBean<SysDataDictionaryCategoryBaseVO> page(String code, String name,
                                                                     Integer pageNo, Integer pageSize) {

        return sysDataDictionaryCategoryClient.page(code, name, pageNo, pageSize);
    }

    /**
     * 列表查询 - 数据字典分类
     *
     * @return {@link APIResponseBean }<{@link List }<{@link SysDataDictionaryCategoryBaseVO }>>
     */
    public APIResponseBean<List<SysDataDictionaryCategoryBaseVO>> list() {

        return sysDataDictionaryCategoryClient.list();
    }
}
